package com.ygxsk.carhome.ui.adapter;

import android.text.TextUtils;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.blankj.utilcode.util.ObjectUtils;
import com.blankj.utilcode.util.StringUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.tencent.mmkv.MMKV;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.constant.ConstantSign;
import com.ygxsk.carhome.response.ShopCartApplyforBean;
import com.ygxsk.carhome.utils.CommUtils;

import java.math.BigDecimal;
import java.util.List;

/**
 * Autuhor:itchen
 * Time:2019/11/14 0014  14:37
 * Description: this is 退货详情之中的适配器内容
 */
public class ApplyForDetailAdapter extends BaseQuickAdapter<ShopCartApplyforBean, BaseViewHolder> {


    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param layoutResId The layout resource id of each item.
     * @param data        A new list is created out of this one to avoid mutable list
     */
    public ApplyForDetailAdapter(int layoutResId, @Nullable List<ShopCartApplyforBean> data) {
        super(layoutResId, data);
    }

    /**
     * Implement this method and use the helper to adapt the view to the given item.
     *
     * @param helper A fully initialized helper.
     * @param item   The item that needs to be displayed.
     */
    @Override
    protected void convert(BaseViewHolder helper, ShopCartApplyforBean item) {

        if (!ObjectUtils.isEmpty(item)) {

            String imageUrl = item.getLogoImg();

            //直接填充数据
            int countInShopCart = item.getProductCount();//商品购物车内的购买数量

            //标题数据
            helper.setText(R.id.textvewititlenameinapplydetail, TextUtils.isEmpty(item.getProductFullName()) ? "" : item.getProductFullName());


            //若 isVipOrder =1;是会员商品 那末不显示商品价格和下边的总价格
            //若 isVipOrder =0;不是会员商品，时普通商品， 那末需要展示商品价格和下边的总价格
            //if (item.getIsVipOrderSon() == 0) {

            //原始代码
            BigDecimal price = item.getSalesPrice();
            //String yangJiao = mSession.getCurrencySymbol();
            //String salePriceFinal = yangJiao + CommUtils.formatComma2BigDecimal(price);

            String salePriceFinal = "";
            if (price != null) {
                salePriceFinal = MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL, StringUtils.getString(R.string.yangjiaocurrencysymbol)) + CommUtils.formatComma2BigDecimal(price);
            } else {
                salePriceFinal = MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL, StringUtils.getString(R.string.yangjiaocurrencysymbol)) + CommUtils.formatComma2BigDecimal(CommUtils.valueOf(0.00));
            }

            helper.setText(R.id.textviewshoppriceinapplydetail, TextUtils.isEmpty(salePriceFinal) ? "" : salePriceFinal);


            //} else if (item.getIsVipOrderSon() == 1) {

            //是会员产品 不展示价格
            //helper.setText(R.id.textviewshoppriceinapplydetail, "");

            //}


            //商品的数量
            helper.setText(R.id.textviewcountrightinapplydetail, "x" + (TextUtils.isEmpty(String.valueOf(countInShopCart)) ? "0" : String.valueOf(countInShopCart)));


            Glide.with(getContext())//
                    .load(imageUrl.trim())//
                    //.transition(withCrossFade())
                    .placeholder(R.drawable.icon_errorfang)//
                    .error(R.drawable.icon_errorfang)//
                    .fallback(R.drawable.icon_errorfang)//
                    .into((ImageView) helper.getView(R.id.imageviewinapplydetail));//


        }

    }
}
